#ifdef TIXML_USE_TICPP

#include "fuXmlSvnLogs.h"
#include "fuFunctions.h"

BEGIN_NAMESPACE_CPPX

//////////////////////////////////////////////////////////////////////////
fuXmlSvnLogEntry::fuXmlSvnLogEntry( const fuString & revision ) :
m_revision(revision)
{

}

fuXmlSvnLogEntry::~fuXmlSvnLogEntry( void )
{

}

bool
fuXmlSvnLogEntry::VisitEnter( const ticpp::Element& element, const ticpp::Attribute* firstAttribute )
{
	fuString node = element.Value();
	if( node == "logentry" ){
		return true;
	}
	if( node == "author" ){
		m_author = element.GetText(false);
		return false;
	}
	if( node == "date" ){
		m_date = element.GetText(false);
		return false;
	}
	if( node == "msg" ){
		m_msg = element.GetText(false);
		return false;
	}

	fuString msg = fuString("fuXmlSvnLogEntry Unknown node :") + node + "\n";
	PrintDebugString(msg.c_str());
	return false;
}

//////////////////////////////////////////////////////////////////////////
fuXmlSvnLogs::fuXmlSvnLogs(void)
{
}

fuXmlSvnLogs::~fuXmlSvnLogs(void)
{
	Release();
}

void
fuXmlSvnLogs::Release( void )
{
	foreach(fuXmlSvnLogEntry * item, Logs){
		delete item;
	}
	Logs.clear();
	m_doc.Clear();
}

bool
fuXmlSvnLogs::Parse( const fuString & src )
{
	Release();

	try{
		m_doc.Parse(src.c_str());
		if( m_doc.NoChildren() )
			return false;

		return m_doc.Accept(this);
	}
	catch(ticpp::Exception & ex){
		PrintDebugString(ex.what());
	}

	return false;
}

bool
fuXmlSvnLogs::VisitEnter( const ticpp::Element& element, const ticpp::Attribute* firstAttribute )
{
	fuString node = element.Value();
	if( node == "log" ){
		return true;
	}
	if( node == "logentry" ){
		fuString revision = element.GetAttribute("revision");
		Logs.push_back(new fuXmlSvnLogEntry(revision));
		element.Accept(Logs.back());
		return false;
	}

	fuString msg = fuString("fuXmlSvnLogs Unknown node :") + node + "\n";
	PrintDebugString(msg.c_str());
	return false;
}

END_NAMESPACE_CPPX

#endif
